package com.newcoder.community.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author edison
 * @version 2023
 * @date 2024/1/20 12:39
 */

@Configuration
public class KaptchaConfig {

    @Bean
    public Producer kaptchaProducer(){
        Properties properties = new Properties();
        properties.setProperty("kaptcha.image.width","100");//设置图片宽度
        properties.setProperty("kaptcha.image.height","40");//设置图片高度
        properties.setProperty("kaptcha.textproducer.font.size","32");//设置字体大小
        properties.setProperty("kaptcha.textproducer.font.color","0,0,0");//设置字体颜色
        properties.setProperty("kaptcha.textproducer.char.string","0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");//设置字体内容
        properties.setProperty("kaptcha.textproducer.char.length","4");//设置字体长度
        properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");//设置干扰线的样式
        properties.setProperty("kaptcha.obscurificator.impl","com.google.code.kaptcha.impl.ShadowGimpy");//设置干扰线的样式
        properties.setProperty("kaptcha.textproducer.char.space","4");//设置字体间隔
        properties.setProperty("kaptcha.background.clear.from","220,220,220");//设置背景颜色



        DefaultKaptcha kaptcha = new DefaultKaptcha();
        Config config = new Config(properties);


        kaptcha.setConfig(config);
        return kaptcha;
    }


}
